package com.itstherules.jmsunit.mock.store;

import java.util.LinkedList;
import java.util.List;

import javax.jms.Message;

import com.itstherules.jmsunit.expectation.JmsExpectation;

public final class CompositeExpectation implements JmsExpectation {
	
	List<JmsExpectation> expectations = new LinkedList<JmsExpectation>();

	public void compute(Message actual) throws AssertionError {
		for (JmsExpectation expectation : expectations) {
			expectation.compute(actual);
		}
	}

	public final void add(JmsExpectation expectation) {
		this.expectations.add(expectation);
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("The Expectations are: ");
		if(expectations.isEmpty()){
			buffer.append("empty");
		} else {
			for (JmsExpectation expectation : expectations) {
				buffer.append("[");
				buffer.append(expectation);
				buffer.append("]");
			}
		}
		return buffer.toString();
	}

}
